<style>
	#think_page_trace {
		box-sizing: unset !important;
	}

	#think_page_trace * {
		box-sizing: unset !important;
	}
</style>
<div id="think_page_trace" style="position: fixed;bottom:0;right:0;font-size:14px;width:100%;z-index: 999999;color: #000;text-align:left;font-family:'微软雅黑';">
	<div id="think_page_trace_tab" style="display: none;background:white;margin:0;height: 50vh;">
		<div id="think_page_trace_tab_tit" style="height:30px;padding: 6px 12px 0;border-bottom:1px solid #ececec;border-top:1px solid #ececec;font-size:16px">
			<span style="color:#000;padding-right:12px;height:30px;line-height:30px;display:inline-block;margin-right:3px;cursor:pointer;font-weight:700">基本</span>
			<span style="color:#000;padding-right:12px;height:30px;line-height:30px;display:inline-block;margin-right:3px;cursor:pointer;font-weight:700">文件</span>
			<span style="color:#000;padding-right:12px;height:30px;line-height:30px;display:inline-block;margin-right:3px;cursor:pointer;font-weight:700">流程</span>
			<span style="color:#000;padding-right:12px;height:30px;line-height:30px;display:inline-block;margin-right:3px;cursor:pointer;font-weight:700">错误</span>
			<span style="color:#000;padding-right:12px;height:30px;line-height:30px;display:inline-block;margin-right:3px;cursor:pointer;font-weight:700">SQL</span>
			<span style="color:#000;padding-right:12px;height:30px;line-height:30px;display:inline-block;margin-right:3px;cursor:pointer;font-weight:700">调试</span>
		</div>
		<div id="think_page_trace_tab_cont" style="overflow:auto;height:calc(50vh - 38px);padding:0;line-height: 24px">
			<div style="display:none;">
				<ol style="padding: 0; margin:0">
					<?php
					// 获取所有已加载的文件列表
					$loaded_files = get_included_files();
					foreach ($loaded_files as $key => $value) {
						// 获取文件大小，单位为字节
						$file_size_bytes = filesize($value);
						// 将字节转换为 KB
						$file_size_kb = $file_size_bytes / 1024;
						// 保留两位小数
						$size = round($file_size_kb, 2);
						$loaded_files[$key] .= " ( $size KB )";
					}
					$DbLog = think\facade\DbLog::list();
					// 获取当前时间
					$timestamp = date('Y-m-d H:i:s');
					// 获取 HTTP 请求方法
					$method = $_SERVER['REQUEST_METHOD'];
					// 获取请求的 URL
					$url = $this->request->getUrlPrefix() . $_SERVER['REQUEST_URI'];
					// 获取 HTTP 协议版本
					$protocol = $_SERVER['SERVER_PROTOCOL'];
					?>
					<li style="border-bottom:1px solid #EEE;font-size:14px;padding:0 12px">请求信息 : <?= "{$timestamp} {$protocol} {$method} : {$url}" ?></li>
					<?php
					// 模拟文件加载数量
					$file_loads = count($loaded_files);
					$runtime = number_format(microtime(true) - JOE_START_TIME, 10, '.', '');
					$reqs    = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞';
					$mem     = number_format((memory_get_usage() - JOE_START_MEMORY) / 1024, 2);
					$runtime = number_format((float) $runtime, 6);
					?>
					<li style="border-bottom:1px solid #EEE;font-size:14px;padding:0 12px"><?= "运行时间 : {$runtime}s [ 吞吐率：{$reqs}req/s ] 内存消耗：{$mem}kb 文件加载：{$file_loads}个" ?></li>
					<li style="border-bottom:1px solid #EEE;font-size:14px;padding:0 12px">查询信息 : <?= count($DbLog) ?> queries</li>
					<li style="border-bottom:1px solid #EEE;font-size:14px;padding:0 12px">缓存信息 : 0 reads,0 writes</li>
					<?php $session_id = session_id() ?>
					<li style="border-bottom:1px solid #EEE;font-size:14px;padding:0 12px"><?= "会话信息 : SESSION_ID={$session_id}" ?></li>
				</ol>
			</div>
			<div style="display:none;">
				<ol style="padding: 0; margin:0">
					<?php
					foreach ($loaded_files as $value) {
						echo '<li style="border-bottom:1px solid #EEE;font-size:14px;padding:0 12px">' . $value . '</li>';
					}
					?>
				</ol>
			</div>
			<div style="display:none;">
				<ol style="padding: 0; margin:0"></ol>
			</div>
			<div style="display:none;">
				<ol style="padding: 0; margin:0"></ol>
			</div>
			<div style="display:none;">
				<ol style="padding: 0; margin:0">
					<?php
					foreach ($DbLog as $value) {
						echo '<li style="border-bottom:1px solid #EEE;font-size:14px;padding:0 12px">' . htmlentities($value) . '</li>';
					}
					?>
				</ol>
			</div>
			<div style="display:none;">
				<ol style="padding: 0; margin:0"></ol>
			</div>
		</div>
	</div>
	<div id="think_page_trace_close" style="display:none;text-align:right;height:15px;position:absolute;top:10px;right:12px;cursor:pointer;">
		<img style="vertical-align:top;" src="" />
	</div>
</div>
<div id="think_page_trace_open" style="height:30px;float:right;text-align:right;overflow:hidden;position:fixed;bottom:0;right:0;color:#000;line-height:30px;cursor:pointer;z-index: 99999999999999999;">
	<div style="background:#232323;color:#FFF;padding:0 6px;float:right;line-height:30px;font-size:14px"><?= $runtime ?> </div>
	<img width="30" title="ShowPageTrace" src="">
</div>
<script type="text/javascript">
	(function() {
		var tab_tit = document.getElementById('think_page_trace_tab_tit').getElementsByTagName('span');
		var tab_cont = document.getElementById('think_page_trace_tab_cont').getElementsByTagName('div');
		var open = document.getElementById('think_page_trace_open');
		var close = document.getElementById('think_page_trace_close').children[0];
		var trace = document.getElementById('think_page_trace_tab');
		var cookie = document.cookie.match(/thinkphp_show_page_trace=(\d\|\d)/);
		var history = (cookie && typeof cookie[1] != 'undefined' && cookie[1].split('|')) || [0, 0];
		open.onclick = function() {
			trace.style.display = 'block';
			this.style.display = 'none';
			close.parentNode.style.display = 'block';
			history[0] = 1;
			document.cookie = 'thinkphp_show_page_trace=' + history.join('|')
		}
		close.onclick = function() {
			trace.style.display = 'none';
			this.parentNode.style.display = 'none';
			open.style.display = 'block';
			history[0] = 0;
			document.cookie = 'thinkphp_show_page_trace=' + history.join('|')
		}
		for (var i = 0; i < tab_tit.length; i++) {
			tab_tit[i].onclick = (function(i) {
				return function() {
					for (var j = 0; j < tab_cont.length; j++) {
						tab_cont[j].style.display = 'none';
						tab_tit[j].style.color = '#999';
					}
					tab_cont[i].style.display = 'block';
					tab_tit[i].style.color = '#000';
					history[1] = i;
					document.cookie = 'thinkphp_show_page_trace=' + history.join('|')
				}
			})(i)
		}
		parseInt(history[0]) && open.click();
		tab_tit[history[1]].click();
	})();
</script>